package com.briup.pts.web.controller;

import com.briup.pts.aop.Logger;
import com.briup.pts.config.response.Result;
import com.briup.pts.domain.bean.Disease;
import com.briup.pts.domain.bean.DiseaseRecord;
import com.briup.pts.domain.vo.RecordWithDisease;
import com.briup.pts.service.DiseaseRecordService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wy
 * @description
 * @data 2024/11/27  11:35
 */
@Tag(name = "病症模块")
@Slf4j
@RequestMapping("/diseaseRecord")
@RequiredArgsConstructor
@RestController
public class DiseaseRecordController {
    private final DiseaseRecordService service;
    //查询所有病症类型信息
    @Operation(summary = "查询所有病症类型信息")
    @GetMapping("/queryAllDisease")
    public Result<List<Disease>> queryAllDisease() {
        List<Disease> list = service.queryAllDisease();
        return Result.success(list)
                .apply("查询成功");
    }

    //分页查询
    @Operation(summary = "分页多条件查询病症记录")
    @GetMapping("/query")
    public Result<?> pageQuery(Integer drDId,String drStatus,
                               @NotNull(message = "分页参数不能为空")
                               @Min(value = 1L, message = "当前页面不能小于1") Integer pageNum,
                               @Min(value = 1L, message = "页面大小不能小于1")
                               @NotNull(message = "分页参数不能为空") Integer pageSize) {
        // 调用service层方法，时间分页多条件查询
        PageInfo<RecordWithDisease> pageInfo = service
                .pageQueryByCondition(drDId,drStatus,pageNum, pageSize);

        return Result.success(pageInfo)
                .apply("获取成功");
    }

    // 单删
    @Logger("根据记录ID删除病症记录")
    @Operation(summary = "根据记录ID删除病症记录")
    @DeleteMapping("/deleteById/{drId}")
    public Result<?> deleteById(@PathVariable Integer drId) {
        service.deleteById(drId);
        return Result.success(null)
                .apply("删除成功");
    }


    // 批量删除，id数组是通过json格式字符串传输的数据，在请求体中获取
    @Logger("批量删除病症记录")
    @Operation(summary = "批量删除病症记录")
    @DeleteMapping("/deleteByIdAll")
    public Result<?> deleteByIdAll(
            @NotEmpty(message = "没有要删除的病症记录")
            @RequestBody List<Integer> ids) {
        // 批量删除数据
        service.deleteByIdAll(ids);
        return Result.success(null)
                .apply("批量删除成功");
    }

    //更新或新增接口
    @Logger("新增或更新病症记录")
    @Operation(summary = "新增或更新病症记录")
    @PostMapping("/saveOrUpdate")
    public Result<?> saveOrUpdate(@RequestBody DiseaseRecord diseaseRecord) {
        service.saveOrUpdate(diseaseRecord);
        return Result.success();
    }
}
